// hyb_yl/zhuanjiasubpages/pages/edit/edit.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    upload_picture_list: [],
    typedate: 0
  },
  uploadimg: function () {
    let that = this;
    var uniacid = app.siteInfo.uniacid
    var data_arr = that.data.upload_picture_list;
    wx.chooseImage({
      count: 5,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        for (var i = 0; i < tempFilePaths.length; i++) {
          wx.uploadFile({
            url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Uploadback&m=hyb_yl',
            filePath: tempFilePaths[i],
            name: 'upfile',
            formData: [],
            success: function (res) {
              console.log(res)
              data_arr.push(res.data)
              that.setData({
                upload_picture_list: data_arr,
                typedate: 1
              })
            }
          })
        }
      }
    })
  },
  handleContentInput: function (e) {
    this.setData({
      text: e.detail.value
    })
  },
  submit: function (e) {
    var that = this
    var val = this.data.text,
      typedate = this.data.typedate,
      upload_picture_list = this.data.upload_picture_list;
    var id = that.data.id
    var zid = that.data.zid
    var orders = that.data.orders
    var arr = {
      'text': val,
      'typedate': typedate,
      'upload_picture_list': upload_picture_list,
    }
    if (that.data.key_words == 'tijianjiedu') {
      //添加报告建议  back_orser=14833566621594394374&zid=22&id=1&wzid=77&key_words=tijianjiedu
      app.util.request({
        'url': 'entry/wxapp/tijian.addsuggest',
        data: {
          data: arr,
          back_orser: that.data.back_orser,
          zid: zid,
          wzid: that.data.wzid,
          id: that.data.id,
        },
        success: function (res) {
          console.log(res)
          wx.showToast({
            title: '提交成功',
            icon: 'none',
            success: function () {
              wx.navigateTo({
                url: '/hyb_yl/mysubpages/pages/backstageIndex/backstageIndex',
              })
            }
          })
        }
      })
    } else {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.adduserzhuiwen',
        data: {
          arr: arr,
          orders: orders,
          zid: zid
        },
        success: function (res) {
          console.log(res)
          //提醒医生
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
            data: {
              id: id,
              val: val,
              near: '图文',
              zid: zid
            },
            success: function (res) {
              console.log(res)
            }
          })
          app.util.request({
            'url': 'entry/wxapp/tuwen.detail',
            data: {
              orders: orders,
              openid: wx.getStorageSync('openid')
            },
            success: function (res) {
              console.log(res)
              that.setData({
                detail: res.data,
                addnum: parseInt(res.data.addnum),
                ifpay: res.data.ifpay
              })
              wx.navigateBack({
                delta: 1,
              })
            }
          })
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    if (options.key_words == 'tijianjiedu') {
      wx.setNavigationBarTitle({
        title: '解读患者报告，综合建议'
      })
      var key_words = options.key_words
      that.setData({
        key_words: key_words,
        id: options.id, //体检订单id
        back_orser: options.back_orser,
        zid: options.zid,
        wzid: options.wzid
      })
    } else {
      var back_orser = options.back_orser
      var zid = options.zid
      var id = options.id
      that.setData({
        orders: back_orser,
        zid: zid,
        id: id
      })
    }

    app.util.request({
      'url': 'entry/wxapp/hzbingli.url',
      success: function (res) {
        console.log(res)
        that.setData({
          url: res.data,
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },


})